package com.study.system.service;

import com.study.system.entity.News;
import com.study.system.mapper.NewsMapper;
import com.study.system.vo.NewsInfoVO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewsService {

    @Resource
    private NewsMapper newsMapper;

    /**
     * 根据社团ID查询发表的所有新闻
     *
     * @param clubId 社团Id
     * @return 查询结果
     */
    public List<NewsInfoVO> findAllClubNews(Integer clubId) {
        return newsMapper.selectAllClubNews(clubId);
    }

    public Boolean deleteNewsById(Integer newsId) {
        return newsMapper.deleteNewsById(newsId) == 1;
    }

    public Boolean modifyNews(Integer id, String title, String content, String time, Integer clubId) {
        return newsMapper.modifyNews(id, title, content, time, clubId) == 1;
    }

    public Boolean createNews(Integer userId, Integer clubId, String title, String content, String time) {
        return newsMapper.insertNews(userId, clubId, title, content, time) == 1;
    }

    public List<NewsInfoVO> searchNewsByTitle(News news) {
        return newsMapper.selectNewsByTitle(news.getTitle(),news.getClubId());
    }
}
